const express = require('express');
const studentmod = require('../module/student');
const  studentrouter= express.Router();
studentrouter.post('/login',(req,res)=>{
    let data =  req.body;
    studentmod.login(data, (err,data)=>{
        if(err){
            console.log(err);
            res.send({status:0,err:'databases err'})
        }else{
             res.send({status:1,data:data});
            }
        })
    });
studentrouter.get('',(req,res)=>{
    let studentGuid = req.query.user_number;
     if(studentGuid){
         studentmod.info(studentGuid, (err,data)=>{
             if(err){
                  res.send({status:0,err:'databases err'});
             }else{
                 res.send({status:1,data:data});
             }
         })
     }else{
         ree.send({status:0,err:'studentGuid is required'})
     }
});
//注册
studentrouter.post('/register',(req,res)=>{
    studentmod.register(req.body,(data)=>{
       res.send(({status:1,data}));
   })
});
//密码修改
studentrouter.post('/updatepassword',(req,res)=>{
   studentmod.updatePassWord(req.body,(data)=>{
       res.send(({status:'1',data:'密码修改成功'}));
   })
});
//个人信息修改
studentrouter.post('/update',(req,res)=>{
   studentmod.update(req.body,(data)=>{
       res.send({status:1,data:'个人信息修改成功'});
   })
});
//找回密码
studentrouter.post('/find',(req,res)=>{
   studentmod.findPassWord(req.body,(data)=>{
       if(data.affectedRows==0){
           res.send({status:0,data:'找回密码失败'});
       }else {
           res.send({status:1,data:'找回密码成功'});
       }
   })
});
//获取密保问题
studentrouter.get('/problem',(req,res)=>{
   studentmod.getProblemList((data)=>{
       res.send({status:1,data});
   })
});
module.exports = studentrouter;
